package com.sdhs.paas.rc.service;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.github.pagehelper.Page;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;
import com.sdhs.paas.rc.bean.DocInfoVersionBean;
import com.sdhs.paas.rc.repository.DocInfoVersionMapper;
import com.sdhs.paas.sdk.base.common.entity.PaginationEntity;
import com.github.pagehelper.PageHelper;

/**
* 描述：DocInfoVersionService 服务接口
* @author kangjichang
* @date 2018-12-10
*/

@EnablePaasMybatis
@MapperScan("com.sdhs.paas.rc.repository")
@Service
public class DocInfoVersionService extends BaseDao<DocInfoVersionBean, DocInfoVersionMapper, Integer>{
		@Override
		public String getMapperNamespace() {
			return DocInfoVersionMapper.class.getName();
		}
		
		@Autowired
		private DocInfoVersionMapper docInfoVersionMapper;
		
		public PaginationEntity<DocInfoVersionBean> getPageDocInfoVersionList(BasePage pageRequest, DocInfoVersionBean docInfoVersionBean) {
			Page<DocInfoVersionBean> pageTotal = PageHelper.startPage(pageRequest.getPage(), pageRequest.getPageSize(),true, false);
			List<DocInfoVersionBean> list = docInfoVersionMapper.getList(docInfoVersionBean);
			PaginationEntity<DocInfoVersionBean> paginationEntity = new PaginationEntity<DocInfoVersionBean>(list,
	                (int) pageTotal.getTotal());
			return paginationEntity;
		}
		
		@Transactional(rollbackFor = Exception.class)
		public boolean saveDocInfoVersion(DocInfoVersionBean docInfoVersionBean) {
			try {
				//ucAppBean.setCtime(System.currentTimeMillis());
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = docInfoVersionMapper.insertDocInfoVersion(docInfoVersionBean);
				return count == 1;
			} catch (Exception e) {
				e.printStackTrace();
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		@Transactional(rollbackFor = Exception.class)
		public boolean updateDocInfoVersion(DocInfoVersionBean docInfoVersionBean) {
			try {
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = docInfoVersionMapper.updateDocInfoVersion(docInfoVersionBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		public DocInfoVersionBean getDocInfoVersionDetail(String id) {
			return docInfoVersionMapper.getDocInfoVersionDetail(id);
		}
		
		public boolean deleteDocInfoVersion(DocInfoVersionBean docInfoVersionBean){
			return docInfoVersionMapper.deleteDocInfoVersion(docInfoVersionBean)>0;
		}
      
}